package com.itheima.media.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.dfs.feign.DfsFeign;
import com.itheima.media.mapper.WmMaterialMapper;
import com.itheima.media.pojo.WmMaterial;
import com.itheima.media.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 自媒体图文素材信息表 服务实现类
 * </p>
 *
 * @author 作者
 * @since 2021-08-20
 */
@Service
public class WmMaterialServiceImpl extends ServiceImpl<WmMaterialMapper, WmMaterial> implements WmMaterialService {

    @Autowired
    private WmMaterialMapper wmMaterialMapper;

    @Autowired
    private DfsFeign dfsFeign;

    /**
     * 修改素材
     * @param wmMaterial
     */
    @Override
    public void updateByIdAndDelFile(WmMaterial wmMaterial) {
        //查询地址
        WmMaterial storeWmMaterial = wmMaterialMapper.selectById(wmMaterial.getId());

        //1：修改数据
        wmMaterialMapper.updateById(wmMaterial);

        //2：删除文件  http://192.168.211.136/
        dfsFeign.delete(storeWmMaterial.getUrl());
    }
}
